@GetMapping("/user")
public ResponseEntity<?> getUser(@RequestParam(required = false) String userId) {
    if (userId == null || !userId.matches("\\d+")) {
        return ResponseEntity.badRequest().body("Invalid or missing userId");
    }
    Integer parsedUserId = Integer.parseInt(userId);
    // logic to get user by id using parsedUserId